import json
import os

pwd = os.path.abspath(os.path.join(os.getcwd()))


def text_mess(user_name=None, user_password=None, user_id=None, action_type=None, mess_num=None):
    if action_type == 'create_true' and mess_num:
        return f'Wiki账户为:\n\n' \
               f'  账户:    {user_name}\n' \
               f'  密码:    {user_password}\n' \
               f'<at user_id=\"{user_id}\"></at>'
    elif action_type == 'create' and mess_num is False:
        return f'新人入职成功,Wiki账户为:\n\n' \
               f'  用户名:    {user_name}\n' \
               f'<at user_id=\"{user_id}\"></at>'
    elif action_type == 'disable_user':
        return f"{user_name},用户已禁用成功."
    elif action_type == 'select_have':
        return f'{user_name}已存在<at user_id=\"{user_id}\"></at>'
    elif action_type == 'select_have_not':
        return f'{user_name}不存在<at user_id=\"{user_id}\"></at>'


def entry_success_card(user_name, user_password):
    with open(f'{pwd}/Static/Cards/Entry.json', 'r') as Entry_success:
        feishu_entry_json_value = json.load(Entry_success)
        Entry_success.close()
        feishu_entry_json_value["elements"][1]["fields"][4]["text"]["content"] = \
            f"**📃  VPN/Wi-Fi/Wiki 账户密码：**\n" \
            f"    账户:  {user_name}\n" \
            f"    密码:  {user_password}\n"

        return feishu_entry_json_value


def entry_false_card(user_name):
    with open(f'{pwd}/Static/Cards/exist.json', 'r') as Entry_false:
        feishu_entry_json_value = json.load(Entry_false)
        Entry_false.close()
        feishu_entry_json_value["elements"][0]["fields"][0]["text"]["content"] = \
            f"账户:  {user_name}已存在相同或相似花名，创建wiki账户失败"

        return feishu_entry_json_value


def change_password_card(user_name, user_password):
    with open(f'{pwd}/Static/Cards/Change.json', 'r') as Change_password:
        feishu_wifi_json = json.load(Change_password)
        Change_password.close()
        feishu_wifi_json["elements"][0]["fields"][0]["text"]["content"] = \
            f"**📃  VPN/Wi-Fi/Wiki 账户密码：**\n"\
            f"   账户:  {user_name}\n"\
            f"   密码:  {user_password}\n"

        return feishu_wifi_json


def change_password_text(user_name, user_password):
    return f"VPN/Wi-Fi/Wiki 账户密码：\n" \
           f"    账户:  {user_name}\n" \
           f"    密码:  {user_password}\n"
